﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Traceability_Management.Domain;
using Traceability_Management.ErrorCode;
using Traceability_Management.Read.Api.Application.Command.HealthyWay;

namespace Traceability_Management.Read.Api.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class HealthyAllController : ControllerBase
    {
        IMediator mediator;

        public HealthyAllController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        [HttpPost]

        public async Task<ApiResult<int>> AddHealthy(Healthys healthys)
        {
            try
            {
                AddHealthysCommand AddHealthysCommand = new AddHealthysCommand() 
                {
                    Healthys= healthys
                };
                return await mediator.Send(AddHealthysCommand);
            }
            catch (Exception)
            {
                throw;
            }
        }
        [HttpGet]
        public async Task<ApiResult<List<Healthys>>> ShowHealthy( [FromQuery] ShowHealthysCommand request)
        {
            try
            {
                return await mediator.Send(request);
            }
            catch (Exception)
            {
                throw;
            }
        }
        [HttpPost]
        public async Task<ApiResult<int>> UpdateHealthy(Healthys Healthys)
        {
            try
            {
                UpdateHealthyCommand UpdateHealthyCommand = new UpdateHealthyCommand()
                {
                    Healthys = Healthys
                };
                return await mediator.Send(UpdateHealthyCommand);
            }
            catch (Exception)
            {
                throw;
            }
        }
        [HttpGet]
        public async Task<ApiResult<int>> DelHealthy([FromQuery] DelHealthyCommand request)
        {
            try
            {
                return await mediator.Send(request);
            }
            catch (Exception)
            {
                throw;
            }
        }
    }
}
